import type { RouteLocationNormalized } from 'vue-router'
import type { RouteMeta } from '@/types'

/**
 * 获取路由的完整面包屑路径
 */
export function getBreadcrumb(route: RouteLocationNormalized): string[] {
  const breadcrumb: string[] = []
  
  if (route.meta?.breadcrumb) {
    breadcrumb.push(...(route.meta.breadcrumb as string[]))
  }
  
  return breadcrumb
}

/**
 * 检查用户是否有访问路由的权限
 */
export function hasRoutePermission(
  route: RouteLocationNormalized,
  userRole?: string
): boolean {
  const meta = route.meta as RouteMeta
  
  // 不需要认证的路由
  if (!meta.requiresAuth) {
    return true
  }
  
  // 需要管理员权限的路由
  if (meta.requiresAdmin && userRole !== 'admin') {
    return false
  }
  
  return true
}

/**
 * 获取路由标题
 */
export function getRouteTitle(route: RouteLocationNormalized): string {
  return (route.meta?.title as string) || '未知页面'
}

/**
 * 检查路由是否应该在导航中显示
 */
export function shouldShowInNav(route: RouteLocationNormalized): boolean {
  return (route.meta?.isShow as boolean) ?? false
} 